//
//  ASNetworkEngine.h
//
//  Created by dfangjun on 16-2-14.
//  Copyright (c) dfangjun. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <Availability.h>
#import <MobileCoreServices/MobileCoreServices.h>

//#import "AFHTTPRequestOperation.h"
#import "AFURLResponseSerialization.h"
#import "AFURLRequestSerialization.h"
#import "AFSecurityPolicy.h"
#import "AFNetworkReachabilityManager.h"

static dispatch_queue_t  downImageQueue = NULL;

@interface ASNetworkEngine : NSObject

//请求地址
@property (readonly, nonatomic, strong) NSURL *requestURL;

//请求序列化
//@property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer;

//返回系列化
//@property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer;

//请求队列
@property (nonatomic, strong) NSOperationQueue *operationQueue;

//网络判断
//@property (readwrite, nonatomic, strong) AFNetworkReachabilityManager *reachabilityManager;


/**
 *  http请求对象获取，单利
 *
 *  @return 返回当前请求对象
 */
+ (instancetype )sharedInstance;

/**
 *  post 请求
 *
 *  @param URLString  请求地址
 *  @param parameters 请求参数
 *  @param success    成功
 *  @param failure    失败
 *
 *  @return 返回请求对象
 */
- (void)POST:(NSString *)URLString
                      parameters:(id)parameters
                         success:(void (^)( id responseObject))success
                         failure:(void (^)( NSError *error))failure;

/**
 *  post 请求
 *
 *  @param URLString        请求地址
 *  @param headParameters   请求参数
 *  @param parameters       请求参数
 *  @param success          成功
 *  @param failure          失败
 *
 *  @return 返回请求对象
 */
- (void)POST:(NSString *)URLString
                  headParameters:(id)parameters
                      parameters:(id)parameters
                         success:(void (^)( id responseObject))success
                         failure:(void (^)( NSError *error))failure;

/**
 *  post 请求
 *
 *  @param URLString      请求地址
 *  @param headParameters 请求头
 *  @param bodyParameters 请求体
 *  @param isBodyEncoding 请求体是否需要编码
 *  @param success        请求成功
 *  @param failure        请求失败
 *
 *  @return 返回请求对象
 */
- (void)POST:(NSString *)URLString
                  headParameters:(id)headParameters
                  bodyParameters:(id)bodyParameters
                  isBodyEncoding:(BOOL)isBodyEncoding
                         success:(void (^)( id responseObject))success
                         failure:(void (^)( NSError *error))failure;


- (void)PUT:(NSString *)URLString
                     parameters:(id)parameters
                        success:(void (^)( id responseObject))success
                        failure:(void (^)( NSError *error))failure;

- (void)PUT:(NSString *)URLString
                 headParameters:(id)headParameters
                     parameters:(id)parameters
                        success:(void (^)( id responseObject))success
                        failure:(void (^)( NSError *error))failure;
/**
 *  get 请求
 *
 *  @param URLString  请求地址
 *  @param parameters 请求参数
 *  @param success    成功
 *  @param failure    失败
 *
 *  @return 返回请求对象
 */
- (void)GET:(NSString *)URLString
                     parameters:(id)parameters
                        success:(void (^)( id responseObject))success
                        failure:(void (^)( NSError *error))failure;


/**
 *  get 请求
 *
 *  @param URLString  请求地址
 *  @param headParameters 请求head设置
 *  @param parameters     请求参数
 *  @param success        成功
 *  @param failure        失败
 *
 *  @return 返回请求对象
 */

- (void)GET:(NSString *)URLString
                 headParameters:(NSDictionary*)headParameters
                     parameters:(id)parameters
                        success:(void (^)( id responseObject))success
                        failure:(void (^)( NSError *error))failure;

/**
 *  get 请求
 *
 *  @param URLString  请求地址
 *  @param headParameters 请求head设置
 *  @param parameters     请求参数
 *  @param downLoadProgress 下载进度
 *  @param success          成功
 *  @param failure          失败
 *
 *  @return 返回请求对象
 */
- (void)GET:(NSString *)URLString
                 headParameters:(NSDictionary*)headParameters
                     parameters:(id)parameters
               DownloadProgress:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))downLoadProgress
                        success:(void (^)( id responseObject))success
                        failure:(void (^)( NSError *error))failure;

/**
 *  下载图片
 *
 *  @param URLString  请求地址
 *  @param parameters 请求参数
 *  @param success    成功
 *  @param failure    失败
 *  @return 返回请求对象
 */
- (void)GETImage:(NSString *)URLString
                          parameters:(id)parameters
                             success:(void (^)( id responseObject))success
                             failure:(void (^)( NSError *error))failure;
/**
 *  下载图片
 *
 *  @param URLString  请求地址
 *  @param parameters 请求参数
 *  @param downLoadProgress 下载进度
 *  @param success    成功
 *  @param failure    失败
 *  @return 返回请求对象
 */
- (void)GETImage:(NSString *)URLString
                          parameters:(id)parameters
                    DownloadProgress:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))downLoadProgress
                             success:(void (^)( id responseObject))success
                             failure:(void (^)( NSError *error))failure;

/**
 *  @brief  下载文件
 *
 *  @param url             被下载的文件url
 *  @param savePath        将下载的文件保存到本地的全路径，包括文件名
 *  @param progressBlock   下载进度回调
 *  @param completionBlock 下载完成回调
 *  @param failure         失败回调
 */
- (void)downloadWithUrl:(NSString *)url
               savePath:(NSString *)savePath
          progressBlock:(void (^)(long long bytesRead, long long totalBytes))progressBlock
        completionBlock:(void (^)(id responseObject))completionBlock
                failure:(void (^)(NSString* errorMsg))failure;


/**
 *  @brief  上传图片
 *
 *  @param url               服务器url
 *  @param image             图片
 *  @param progressBlock     过程回调
 *  @param completionBlock   成功回调
 *  @param failure           失败回调
 */

- (void)uploadImageWithUril:(NSString *)url
                      image:(UIImage *)image
              progressBlock:(void (^)(long long bytesRead, long long totalBytes))progressBlock
            completionBlock:(void (^)(id responseObject))completionBlock
                    failure:(void (^)(NSString* errorMsg))failure;

/**
 *  @brief  上传多张图片
 *
 *  @param url               服务器url
 *  @param array             图片
 *  @param progressBlock     过程回调
 *  @param completionBlock   成功回调
 *  @param failure           失败回调
 */

- (void)uploadImagesWithUrl:(NSString *)url
                      image:(NSMutableArray *)imageArray
              progressBlock:(void (^)(long long bytesRead, long long totalBytes))progressBlock
            completionBlock:(void (^)(id responseObject))completionBlock
                    failure:(void (^)(NSString* errorMsg))failure;


/**
 *  @brief  上传视频
 *
 *  @param url               服务器url
 *  @param image             视频
 *  @param progressBlock     过程回调
 *  @param completionBlock   成功回调
 *  @param failure           失败回调
 */
- (void)uploadVideoWithUril:(NSString *)url
                      video:(NSData *)videoData
              progressBlock:(void (^)(long long bytesRead, long long totalBytes))progressBlock
            completionBlock:(void (^)(id responseObject))completionBlock
                    failure:(void (^)(NSString* errorMsg))failure;


- (void)cancelAllHTTPOperationsWithMethod;

- (void)downLoadData:(NSString*)path image:(UIImageView*)imageView;



@end








